package org.openems;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.openems.entity.Entity;
import org.openems.entity.ParameterConverter;
import org.openems.entity.TraceEntity;
import org.openems.meta.ParameterModelMeta;
import org.openems.model.ParameterModel;
import org.slim3.datastore.Datastore;

import com.google.appengine.api.datastore.KeyFactory;

@Path("/tracelist")
@Produces(MediaType.APPLICATION_JSON)
public class TraceListResource {
    @GET
    public StringListEntities get() {
        ParameterModelMeta e = ParameterModelMeta.get();
        List<ParameterModel> models = Datastore.query(e).asList();
        ParameterConverter converter = new ParameterConverter();
        StringListEntities ret = new StringListEntities();
        for (ParameterModel model : models) {
            Entity entity = converter.get(model.getBlob().getBytes());
            if (entity instanceof TraceEntity) {
                ret.list.add(KeyFactory.keyToString(model.getKey()));
            }
        }
        return ret;
    }
}
